#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
  int i=520;
  vector<int> ret;
  while(i--)
  {
    int y;
    int m;
    int d;
    int h;
    int min;
    int s;
    scanf("%d-%d-%d %d:%d:%d",&y,&m,&d,&h,&min,&s);
    int sum=0;
    for(int x=1;x<m;++x)
    {
      sum+=days[x];
    }
    sum+=d;
    sum=sum*24+h;
    sum=sum*60+min;
    sum=sum*60+s;
    ret.push_back(sum);
  }
  sort(ret.begin(),ret.end());
  int finsum=0;
  for(int i=0;i<ret.size();i+=2)
  {
    finsum+=(ret[i+1]-ret[i]);
  }
  cout<<finsum;
  return 0;
}
